package cn.dida.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.dida.dao.GeneralSetDao;
import cn.dida.model.GeneralSet;
import cn.dida.model.Pageable;
import cn.dida.service.GeneralSetService;

/**
 * 账户管理 接口实现类
 * @author Administrator
 *
 */
@Service
public class GeneralSetServiceImpl implements GeneralSetService {
    @Autowired
    private GeneralSetDao generalsetDao;

    @Override
    public List<GeneralSet> query(Integer companyId) {
        List<GeneralSet> list = generalsetDao.query(companyId);

        for(GeneralSet gen:list){
            String itemInfo = gen.getItemInfo();
            if(gen.getSetuptype()==1 && itemInfo != null){
                List<Map<String,Object>> itemInfoList = new ArrayList<>();
                JSONArray json = JSONArray.fromObject(itemInfo);
//                System.out.print(json);
                for (int i = 0; i < json.size(); i++) {
                    JSONObject jsonObj = json.getJSONObject(i);
                    Map<String,Object> map = jsonObj;
                    itemInfoList.add(map);
                }
                gen.setItemInfoList(itemInfoList);
            }

        }
        return list;
    }
    
    @Override
    public boolean insertGeneralSet(GeneralSet generalset) {
        return generalsetDao.insertGeneralSet(generalset);
    }
    
    @Override
    public GeneralSet getGeneralSet(Integer companyId, Integer id){
    	return generalsetDao.getGeneralSet(companyId,id) ;
    }
    
    @Override
    public boolean updateGeneralSet(GeneralSet generalset){
    	return generalsetDao.updateGeneralSet(generalset);
    }
    
    @Override
    public boolean deleteGeneralSet(Integer companyId, Integer id){
    	return generalsetDao.deleteGeneralSet(companyId,id);
    }
    
    @Override
    public List<Map<String, Object>> queryGeneralSetExport(Integer companyId) {
    	return generalsetDao.queryGeneralSetExport(companyId);
    }
    
    @Override
	public  Map<String, Object> queryGeneralSet(Integer companyid){
		return generalsetDao.queryGeneralSet(companyid);
	}
    
}
